﻿Imports System.Data.OleDb

Public Class Form2

    Private Sub DocumentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.DocumentBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DigitalDocumentDataSet)

    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Template' table. You can move, or remove it, as needed.
        Me.TemplateTableAdapter.Fill(Me.DigitalDocumentDataSet.Template)
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Author' table. You can move, or remove it, as needed.
        Me.AuthorTableAdapter.Fill(Me.DigitalDocumentDataSet.Author)
        'TODO: This line of code loads data into the 'DigitalDocumentDataSet.Document' table. You can move, or remove it, as needed.
        Me.DocumentTableAdapter.Fill(Me.DigitalDocumentDataSet.Document)

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TitleTextBox.Text = "") Then
            MsgBox("You must give a title")
        Else
            Me.DocumentTableAdapter.Insert(Me.TitleTextBox.Text, Me.NameComboBox.SelectedValue.ToString, "1", 0, Me.TemplateComboBox.SelectedValue.ToString, Today.Date)

            Dim strSQL As String = "SELECT Max(Did) as cc FROM Document"
            Try
                Using cnn As New OleDbConnection(My.Settings.DigitalDocumentConnectionString)
                    Using cmd As New OleDbCommand(strSQL, cnn)
                        cnn.Open()

                        Using dr As OleDbDataReader = cmd.ExecuteReader()
                            ' Loop through all the rows, retrieving the 
                            ' columns you need. Also look into the GetString
                            ' method (and other Get... methods) for a faster 
                            ' way to retrieve individual columns.

                            While dr.Read
                                Form1.Did = dr("cc")
                                MsgBox(dr("cc"))
                            End While
                            cnn.Close()

                        End Using
                    End Using
                End Using

            Catch ex As Exception
                MessageBox.Show(ex.Message)

            End Try


            MsgBox("Saved")
            Form1.Form1DocText.Text = Me.TitleTextBox.Text
            Form1.Form1TempText.Text = Me.TemplateComboBox.SelectedValue.ToString
            Form1.action = "New"
            Form1.actions()
            Me.Close()

        End If
    End Sub

End Class